# -*- coding: UTF-8 -*-
'''
@Project ：pythonProject 
@File    ：looperDemo.py
@Author  ：siwei
@Date    ：2023/5/23 23:15 
'''
# 循环结构  while和for -in

# if判断一次,条件为True执行一行
# while判断N+1次,条件为True执行N次
# 步骤:1.初始化变量  2.条件判断  3.条件执行体  4.改变变量
a = 0
sum = 0
while a < 5:
    sum += a
    a += 1
print(sum)

# 计算1-100之间的偶数和
a = 1
sum = 0
while a <= 100:
    if a % 2 == 0:
        sum += a
    a += 1
print(sum)

# 计算1-100之间的奇数和
a = 1
sum = 0
while a <= 100:
    if a % 2:   # a%2==0为false,不进入if循环.a%2!=0为True,进入if循环
        sum += a
    a += 1
print(sum)
